\HeaderA{glmm.admb}{Generalized Linear Mixed Models using AD Model Builder}{glmm.admb}
\keyword{models}{glmm.admb}
\begin{Description}\relax
Fits mixed-effects models to count data using Binomial, Poisson or
negative binomial response distributions. Zero-inflated versions of 
Poisson and negative binomial distributions are available.
\end{Description}
\begin{Usage}
\begin{verbatim} glmm.admb(fixed, random, group, data, family = "poisson", link, corStruct = "diag", 
                impSamp = 0, easyFlag = TRUE, zeroInflation = FALSE, imaxfn = 10, save.dir= NULL)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{fixed}] a two-sided linear formula object describing the
fixed-effects part of the model, with the response on the
left of a '~' operator and the terms, separated by '+'
operators, on the right.
\item[\code{random}] optionally, a one-sided formula object describing the
random-effects part of the model. When 'random' is missing
an ordinary GLM without random effects is fitted.
\item[\code{group}] a character string naming the main nesting variable.
\item[\code{data}] a data frame containing the variables named in 'fixed', 'random' and 'group'.
\item[\code{family}] a character string determining the response distribution: "poisson" or "nbinom".
\item[\code{link}] a character string specifying the shape of the link function ("logit" or "probit") used for the "binomial" family.
\item[\code{corStruct}] a character string specifying the covariance structure of the random effects vector. 
Two types of covariance matrices are are currently implemented: "diag" (diagonal matrix) and "full"
(positive definite matrix with all elements being estimated).
\item[\code{impSamp}] integer.  The sample size in the importance sampling correction of the Laplace approximation 
(impSamp=0 yields a plain Laplace approximation).
\item[\code{easyFlag}] logical.  If 'TRUE', a faster but less robust optimization algorithm is employed (only "poisson" and "nbinom").
\item[\code{zeroInflation}] logical.  If 'TRUE', a zero-inflated model is fitted (only "poisson" and "nbinom")
\item[\code{imaxfn}] integer. Number of function evaluations used in intermediate optimization steps.
\item[\code{save.dir}] If a quoted directory name is specified all the ADMB output files are saved there.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
Currently, the "binomial" familiy only accepts Bernoully responce (0 or 1).

Parameterization of the negative binomial distribution: Var(Y) = E(Y)*(1+E(Y)/alpha).

Zero-inflation: With probability '1-pz' Y comes from a Poisson (or negative binomial) distribution,
and with probability 'pz' Y is zero (Bohning et al., 1999). Only available with "poisson" and "nbinom" response.

Parameters are estimated by maximum likelihood using the Laplace approximation to evaluate the marginal 
likelihood. When 'impSamp > 0' importance sampling is used to improve the
Laplace approximation (Skaug and Fournier, 2005).

If the message 'Proper convergence could not be reached' occurs, try to increase the parameter 'imaxfn'
and to set 'easyFlag = FALSE'.
\end{Details}
\begin{Value}
An object of class 'glmm.admb' representing the  model fit. 
The generic function 'print' has a method to show the results of the fit.

\begin{ldescription}
\item[\code{b}] vector of fixed effects
\item[\code{S}] covariance matrix of random effects
\item[\code{alpha}] parameter in negative binomial distribution (only when 'family = "poisson"')
\item[\code{pz}] Zero-inflation parameter (only when 'zeroInflation = TRUE')
\end{ldescription}
\end{Value}
\begin{Author}\relax
H. Skaug skaug@mi.uib.no, David Fournier otter@otter-rsch.com and Anders Nielsen andersn@hawaii.edu
\end{Author}
\begin{References}\relax
Bohning, D. et al (1999). The Zero-Inflated Poisson Model and the Decayed, Missing and Filled Teeth Index in Dental Epidemiology.
Journal of the Royal Statistical Society. Series A (Statistics in Society)  Vol. 162, No. 2 (1999), pp. 195-209.

Skaug and Fournier (2005). Automatic Evaluation of the Marginal Likelihood in Nonlinear Hierarchical Models. Unpublished
available from: http://bemata.imr.no/laplace.pdf
\end{References}
\begin{Examples}
\begin{ExampleCode}
  data(epil2)
  glmm.admb(y~Base*trt+Age+Visit,random=~Visit,group="subject",data=epil2,family="nbinom")
\end{ExampleCode}
\end{Examples}

